package com.silverhaze.web.servlet;

import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;

/**
 * This code is part of Kg.Axion project. Treat as strictly confidential.
 * Author: Ivan Babanin
 * Creation date: 23.01.12 8:49
 */
public class WoTBannerGeneration extends HttpServlet {

    private static final int WIDTH = 100;
    private static final int HEIGHT = 50;

    private static final Color BACKGROUND_COLOR = Color.WHITE;
    private static final Color BORDER_COLOR = Color.WHITE;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
        resp.setContentType("image/png");

        BufferedImage buffer = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
        Graphics g = buffer.createGraphics();
        g.setColor(BACKGROUND_COLOR);
        g.fillRect(0, 0, WIDTH, HEIGHT);

        g.setColor(BORDER_COLOR);
        g.drawRect(0, 0, WIDTH, HEIGHT);

        ServletOutputStream outputStream = resp.getOutputStream();
        ImageIO.write(buffer, "png", outputStream);
        outputStream.close();
    }
}
